package model;

import java.util.HashSet;


public class ModelMulticaster implements ModelListener
{
   private static ModelMulticaster instance                                = null;
   protected HashSet<ModelListener> jpegFrameUpdatedListener = new HashSet<ModelListener>();
   protected HashSet<ModelListener> PSDRefreshedListener = new HashSet<ModelListener>();

   
   public static ModelMulticaster getInstance()
   {
      if (instance == null)
      {
         instance = new ModelMulticaster();
      }
      return instance;
   }
   
   public void add(ModelListener l, int event)
   {
      switch (event)
      {
         case ModelListener.JPEGFRAME_UPDATED:
         {
            jpegFrameUpdatedListener.add(l);
         }
         break;
         case ModelListener.PSD_REFRESHED:
         {
            PSDRefreshedListener.add(l);
         }
         break;
      }
   }
   
   public void remove(ModelListener l, int event)
   {
      switch (event)
      {
         case ModelListener.JPEGFRAME_UPDATED:
         {
            jpegFrameUpdatedListener.remove(l);
         }
         break;
         case ModelListener.PSD_REFRESHED:
         {
            PSDRefreshedListener.remove(l);
         }
         break;
      }
      
   }
   @Override
   public void modelJpegFrameUpdated(ModelJpegFrameUpdatedEvent e)
   {
      for(ModelListener l : jpegFrameUpdatedListener)
      {
         l.modelJpegFrameUpdated(e);
      }
      
   }

   @Override
   public void modelPSDRefreshed(ModelPSDRefreshedEvent e)
   {
      for(ModelListener l : PSDRefreshedListener)
      {
         l.modelPSDRefreshed(e);
      }
   }

}
